<?php

namespace App\Console;

use App\Console\Commands\CalculateDaily;
use App\Console\Commands\MakeDomesticBill;
use App\Console\Commands\TenderCollect;
use App\Models\Admin\AdminSetting;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        MakeDomesticBill::class,
        TenderCollect::class,
        CalculateDaily::class,
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $offline_pay_date=AdminSetting::where('name','offline_pay_date')->value('value');
        $offline_pay_date=$offline_pay_date??'5';
        $schedule->command(MakeDomesticBill::class)->monthlyOn($offline_pay_date, '00:05');

        //判断招标采集时间
        $daily_collect_time=AdminSetting::where('name','daily_collect_time')->value('value');
        if($daily_collect_time)
        {
            $schedule->command(TenderCollect::class)->dailyAt($daily_collect_time.':49');
        }

        $schedule->command(CalculateDaily::class)->dailyAt("23:58:00");
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}
